/*
 * SonarQube PDF Report
 * Copyright (C) 2010-2017 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.report.pdf.util;

/**
 * Example class demonstrating how to read SonarQube configuration similar to PDFReportPlugin
 * This shows the pattern used by SonarQube plugins for configuration
 */
public class SonarConfigExample {

    // Configuration keys matching those in PDFPostJob
    public static final String SONAR_HOST_URL = "sonar.host.url";
    public static final String SONAR_HOST_URL_DEFAULT_VALUE = "http://localhost:9000";
    
    public static final String USERNAME = "sonar.pdf.username";
    public static final String USERNAME_DEFAULT_VALUE = "";
    
    public static final String PASSWORD = "sonar.pdf.password";
    public static final String PASSWORD_DEFAULT_VALUE = "";
    
    public static final String PROJECT_KEY = "sonar.project.key";
    public static final String PROJECT_KEY_DEFAULT_VALUE = "";
    
    public static final String REPORT_TYPE = "report.type";
    public static final String REPORT_TYPE_DEFAULT_VALUE = "workbook";
    
    public static final String SKIP_PDF = "sonar.pdf.skip";
    public static final boolean SKIP_PDF_DEFAULT_VALUE = false;

    /**
     * Get SonarQube host URL from custom configuration
     */
    public static String getSonarHostUrl() {
        return ConfigUtil.getProperty(SONAR_HOST_URL, SONAR_HOST_URL_DEFAULT_VALUE);
    }

    /**
     * Get SonarQube username from custom configuration
     */
    public static String getUsername() {
        return ConfigUtil.getProperty(USERNAME, USERNAME_DEFAULT_VALUE);
    }

    /**
     * Get SonarQube password from custom configuration
     */
    public static String getPassword() {
        return ConfigUtil.getProperty(PASSWORD, PASSWORD_DEFAULT_VALUE);
    }

    /**
     * Get project key from custom configuration
     */
    public static String getProjectKey() {
        return ConfigUtil.getProperty(PROJECT_KEY, PROJECT_KEY_DEFAULT_VALUE);
    }

    /**
     * Get report type from custom configuration
     */
    public static String getReportType() {
        return ConfigUtil.getProperty(REPORT_TYPE, REPORT_TYPE_DEFAULT_VALUE);
    }

    /**
     * Check if PDF generation should be skipped
     */
    public static boolean shouldSkipPdf() {
        return ConfigUtil.getBooleanProperty(SKIP_PDF, SKIP_PDF_DEFAULT_VALUE);
    }

    /**
     * Example method showing how to use SonarQube configuration
     */
    public static void demonstrateSonarConfigUsage() {
        System.out.println("=== SonarQube Configuration Demo ===");
        
        if (ConfigUtil.isConfigAvailable()) {
            System.out.println("SonarQube Host URL: " + getSonarHostUrl());
            System.out.println("Username: " + getUsername());
            System.out.println("Password: " + (getPassword().isEmpty() ? "[empty]" : "******"));
            System.out.println("Project Key: " + getProjectKey());
            System.out.println("Report Type: " + getReportType());
            System.out.println("Skip PDF: " + shouldSkipPdf());
            
            // Example of how this could be used with PDFGenerator
            System.out.println("\nExample usage with PDFGenerator:");
            System.out.println("PDFGenerator generator = new PDFGenerator(");
            System.out.println("    \"" + getProjectKey() + "\",");
            System.out.println("    fileSystem,");
            System.out.println("    \"" + getSonarHostUrl() + "\",");
            System.out.println("    \"" + getUsername() + "\",");
            System.out.println("    \"" + getPassword() + "\",");
            System.out.println("    \"" + getReportType() + "\"");
            System.out.println(");");
            
        } else {
            System.out.println("Custom configuration file not available.");
        }
        
        System.out.println("=====================================");
    }
    
    /**
     * Main method for testing/demonstration
     */
    public static void main(String[] args) {
        demonstrateSonarConfigUsage();
    }
}
